package cn.jekun.shop.common.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import cn.jekun.component.base.bean.Page;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.core.bean.gen.RsApk;

/**
 * 
 * 手机版本信息
 * @author yuanhw
 *
 */
@Service(UpdateService.BEAN_NAME)
public class UpdateService extends ShopBaseService{
	public static final String BEAN_NAME = "cn.jekun.shop.common.service.UpdateService";
	public static final String PKG = "com.duiyidui.activity";//包名
	
	@Override
	public String getNamespace() {
		return "SHOP_UPDATE";
	}
	/**
	 * @return
	 */
	public JSONObject getVersion() {
		JSONObject jsonObject = new JSONObject();
		//基本验证
		try{
			Map map = new HashMap();
			Page page = new Page();
			page.setPageSize(1);
			List<RsApk> apks = this.list(map, page);
			if (apks != null && apks.size() > 0) {
				RsApk apk = apks.get(0);
				String version = apk.getVersion();
				String apkName = apk.getApkName();
				String apkUrl = apk.getApkUrl();
				String memo = apk.getMemo();
				int v = 0;
				try {
					v = Integer.parseInt(version);
				} catch (Exception e) {
				}
				
				jsonObject.put("version", v);//服务端APK的版本（Int）
				jsonObject.put("apkName", apkName);//服务端APK的名称
				jsonObject.put("apkUrl", apkUrl);//服务端APK的下载地址
				jsonObject.put("memo", memo);//服务端升级版本信息
				return this.executeRerutn(jsonObject);
			}
		}catch(BusinessException e){
			throw e;
		}catch(Exception e){
			e.printStackTrace();
		}
		return this.executeRerutnFail(jsonObject);
	}
}
